//
//  YBMYListViewController.m
//  GoodBuy
//
//  Created by Cyber on 15/5/13.
//  Copyright (c) 2015年 GoodBuy. All rights reserved.
//

#import "YBMYListViewController.h"
#import "DKNightVersion.h"
#import "YBForeignListViewController.h"

@interface YBMYListViewController ()

@end

@implementation YBMYListViewController

- (void)viewWillAppear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
   
//    self.view.backgroundColor = [UIColor whiteColor];
    
    self.title = @"MY";

    UIImageView *image2View = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    image2View.image = [UIImage imageNamed:@"MYbackgroun"];
    image2View.contentMode = 2;
    image2View.alpha = 0.5;
    
    // Do any additional setup after loading the view.
    
    self.scrollView = [[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    self.scrollView.contentSize = CGSizeMake(kWidth, kHeight);
    [self.view addSubview:_scrollView];
    _scrollView.scrollEnabled = NO;
    [self.scrollView addSubview:image2View];
    
    self.share = [UIButton buttonWithType:UIButtonTypeCustom];
    _share.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/4 + 10, 50, 100, 50);
    [_share setTitle:@"推荐给朋友" forState:UIControlStateNormal];
    [_share setTitleColor:[UIColor colorWithRed:0.5 green:0.618 blue:1 alpha:1.0] forState:UIControlStateNormal];
    [_share addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
    [_scrollView addSubview:_share];
    
    //意见反馈按钮
    self.feedback = [UIButton buttonWithType:UIButtonTypeCustom];
    _feedback.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/4, 100, 100, 50);
    [_feedback setTitle:@"意见反馈" forState:UIControlStateNormal];
    [_feedback setTitleColor:[UIColor colorWithRed:0.478 green:0.651 blue:0.988 alpha:1.0] forState:UIControlStateNormal];
    [_feedback addTarget:self action:@selector(feedbackAction) forControlEvents:UIControlEventTouchUpInside];
    [_scrollView addSubview:_feedback];
    
    self.collect = [UIButton buttonWithType:UIButtonTypeCustom];
    _collect.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/4, 150, 100, 50);
    [_collect setTitle:@"我的收藏" forState:UIControlStateNormal];
    [_collect setTitleColor:[UIColor colorWithRed:0.478 green:0.651 blue:0.988 alpha:1.0] forState:UIControlStateNormal];
    [_collect addTarget:self action:@selector(collectAction) forControlEvents:UIControlEventTouchUpInside];
    [_scrollView addSubview:_collect];
    
    self.aboutUs = [UIButton buttonWithType:UIButtonTypeCustom];
    _aboutUs.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/4, 300, 100, 50);
    [_aboutUs setTitle:@"关于我们" forState:UIControlStateNormal];
    [_aboutUs setTitleColor:[UIColor colorWithRed:0.478 green:0.651 blue:0.988 alpha:1.0] forState:UIControlStateNormal];
    [_aboutUs addTarget:self action:@selector(aboutUsAction) forControlEvents:UIControlEventTouchUpInside];
    [_scrollView addSubview:_aboutUs];
    
    
    self.huancun = [UIButton buttonWithType:UIButtonTypeCustom];
    _huancun.frame = CGRectMake(200, 250, 100, 50);
    NSString *romNumber = [NSString stringWithFormat:@"%.2fM", [self filePath]];
    [_huancun setTitle:romNumber forState:UIControlStateNormal];
    [_huancun setTitleColor:[UIColor colorWithRed:0.478 green:0.651 blue:0.988 alpha:1.0] forState:UIControlStateNormal];
    [_huancun addTarget:self action:@selector(huancunAction) forControlEvents:UIControlEventTouchUpInside];
    [_scrollView addSubview:_huancun];
    
    UIButton *testbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    testbtn.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/4, 250, 100, 50);
    [testbtn setTitle:@"清理缓存" forState:UIControlStateNormal];
    [testbtn setTitleColor:[UIColor colorWithRed:0.478 green:0.651 blue:0.988 alpha:1.0] forState:UIControlStateNormal];
    [testbtn addTarget:self action:@selector(testAction) forControlEvents:UIControlEventTouchUpInside];
    [_scrollView addSubview:testbtn];
    
    //夜间模式按钮
    self.NightLa = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/4+10, 200, 100, 50)];
    _NightLa.text = @" 夜间模式";
    [_NightLa setTextColor:[UIColor colorWithRed:0.478 green:0.651 blue:0.988 alpha:1.0]];
    [_scrollView addSubview:_NightLa];
    [_NightLa release];
    
    
    int i = 1000;
    self.switch1 = [[UISwitch alloc] initWithFrame:CGRectMake(220, 210, [UIScreen mainScreen].bounds.size.width/4, 30)];
    _switch1.tag = i++;
    [_switch1 addTarget:self action:@selector(switch1Teg:) forControlEvents:UIControlEventValueChanged];
    [_scrollView addSubview:_switch1];
    [_switch1 release];
    
    self.view.nightBackgroundColor = [UIColor colorWithRed:0.141 green:0.145 blue:0.153 alpha:1.0];
    self.navigationController.navigationBar.nightBarTintColor = [UIColor colorWithRed:0.196 green:0.201 blue:0.212 alpha:1.0];
    
}

//关于我们
- (void)aboutUsAction {
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"GoodBuy团队" message:@"陈岩波,蒋明,于景鹏" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];
}

//收藏
- (void)collectAction {
    YBMYTowViewController *collect = [[YBMYTowViewController alloc]init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:collect animated:YES];
    self.hidesBottomBarWhenPushed = NO;

}
//分享
- (void)shareAction {
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"5551988067e58eb48d00103b"
                                      shareText:@"#GoodBuy推荐#我正在使用GoodBuy这款app,这是个不错的购物推荐软件,快来试试吧!"
                                     shareImage:[UIImage imageNamed:@"Good1"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToEmail,UMShareToFacebook,UMShareToTwitter,UMShareToSms,nil]
                                       delegate:self];
}
//清除缓存
- (void)testAction {
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"清除缓存成功" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];
    
    NSString * cachPath = [ NSSearchPathForDirectoriesInDomains ( NSCachesDirectory , NSUserDomainMask , YES ) firstObject ];
    
    NSArray * files = [[ NSFileManager defaultManager ] subpathsAtPath :cachPath];
    
    // NSLog ( @"cachpath = %@" , cachPath);
    
    for ( NSString * p in files) {
        
        NSError * error = nil ;
        
        NSString * path = [cachPath stringByAppendingPathComponent :p];
        
        if ([[ NSFileManager defaultManager ] fileExistsAtPath :path]) {
            
            [[ NSFileManager defaultManager ] removeItemAtPath :path error :&error];
            
        }
    }
    NSString *romNumber = [NSString stringWithFormat:@"%.2fM", [self filePath]];
    [_huancun setTitle:romNumber forState:UIControlStateNormal];
    [_huancun setTitleColor:[UIColor colorWithRed:0.478 green:0.651 blue:0.988 alpha:1.0] forState:UIControlStateNormal];
}


- (void)huancunAction {
    NSString *chch = [ NSString stringWithFormat : @"%.2fM" , [ self filePath ]];
    NSLog(@"++++____++++_+_+_+_+     我的缓存   %@", chch);
    NSString *romNumber = [NSString stringWithFormat:@"%.2fM", [self filePath]];
    [_huancun setTitle:romNumber forState:UIControlStateNormal];
    [_huancun setTitleColor:[UIColor colorWithRed:0.478 green:0.651 blue:0.988 alpha:1.0] forState:UIControlStateNormal];
    
    
}

- (UIColor *)loadTitleViewColor {
    return [UIColor colorWithRed:0.618 green:0.618 blue:0.618 alpha:1];
}
     
     
     
//-------------获取缓存
- ( float )filePath {
    NSString * cachPath = [ NSSearchPathForDirectoriesInDomains ( NSCachesDirectory , NSUserDomainMask , YES ) firstObject ];
    return [ self folderSizeAtPath :cachPath];
}
- ( float ) folderSizeAtPath:( NSString *) folderPath {
    NSFileManager * manager = [ NSFileManager defaultManager ];
    if (![manager fileExistsAtPath :folderPath]) return 0 ;
    NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath :folderPath] objectEnumerator ];
    NSString * fileName;
    long long folderSize = 0 ;
    while ((fileName = [childFilesEnumerator nextObject ]) != nil ){
        NSString * fileAbsolutePath = [folderPath stringByAppendingPathComponent :fileName];
        
        folderSize += [ self fileSizeAtPath :fileAbsolutePath];
        
    }
    
    return folderSize/( 1024.0 * 1024.0 );
    
}
- (long long) fileSizeAtPath:( NSString *) filePath{
    
    NSFileManager * manager = [ NSFileManager defaultManager ];
    
    if ([manager fileExistsAtPath :filePath]){
        
        return [[manager attributesOfItemAtPath :filePath error : nil ] fileSize ];
    }
    return 0 ;
}
//-------获取缓存结束


//夜间模式
-(void)switch1Teg:(UISwitch *)Switch
{
    if (Switch.on) {
        self.view.window.alpha = 0.618;
    }else{
        self.view.window.alpha = 1;
    }
}

//意见反馈按钮按下
- (void)feedbackAction {
    YBFeedbackViewController *feedbackVC = [[YBFeedbackViewController alloc]init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:feedbackVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)negativeButtonAction
{
    NSLog(@"negative Action");
}

- (void)positiveButtonAction
{
    NSLog(@"positive Action");
}

- (void)closeButtonAction
{
    NSLog(@"close Action");
}

- (NSString *)loadTextWithNegativeTitle
{
    //    return nil;
    return @"返回";
}

- (NSString *)loadTextWithTitle
{
    //    return nil;
    return @"亲 把我带回家吧";
}

- (NSString *)loadTextWithPositiveTitle
{
    //    return nil;
    return @"确定";
}

- (NSString *)loadTextWithEnsureTitle
{
    //    return nil;
    return @"收藏成功";
}

- (NSString *)loadTextWithConfirmTitle
{
    //    return nil;
    return @"祝您生活愉快!";
}

@end
